# RUN: llc -mtriple=x86_64-unknown-linux-gnu -run-pass x86-fixup-bw-insts %s -o - -experimental-debug-variable-locations | FileCheck  %s
#
# This test is a copy of llvm/test/CodeGen/X86/fixup-bw-inst.mir, with a few
# test bodies removed. The pass promotes certain register operations to be
# wider operations (such as loads and sign extensions), which has an instruction
# encoding benefit. New instructions are created, and so should have a debug 
# instruction number substitution; but in addition a qualifiying subregister,
# because the newly def'd register is a different size to the old one.
#
# Plain copies that get transformed are not tested for, as they should never
# be instrumented. At a high level, copies do not define a value; they move
# them.

---
# CHECK-LABEL: name: test1
name:            test1
alignment:       16
tracksRegLiveness: true
debugInstrRef: true
liveins:
  - { reg: '$rax' }
# CHECK:     debugValueSubstitutions:
# CHECK-NEXT - { srcinst: 1, srcop: 0, dstinst: 2, dstop: 0, subreg: 4 }
## Subreg 4 -> sub_16bit
body:             |
  bb.0:
    liveins: $rax

    $ax = MOV16rm killed $rax, 1, $noreg, 0, $noreg, debug-instr-number 1
    ; CHECK: $eax = MOVZX32rm16 killed $rax, {{.*}} debug-instr-number 2

    RET64 $ax

...
---
# CHECK-LABEL: name: test3
name:            test3
alignment:       16
tracksRegLiveness: true
debugInstrRef: true
liveins:
  - { reg: '$rdi' }
# CHECK:     debugValueSubstitutions:
# CHECK-NEXT - { srcinst: 1, srcop: 0, dstinst: 2, dstop: 0, subreg: 4 }
## Subreg 4 -> sub_16bit
body:             |
  bb.0:
    successors: %bb.1(0x30000000), %bb.2(0x50000000)
    liveins: $rdi

    TEST64rr $rdi, $rdi, implicit-def $eflags
    JCC_1 %bb.1, 4, implicit $eflags

  bb.2:
    liveins: $rdi

    $ax = MOV16rm killed $rdi, 1, $noreg, 0, $noreg, implicit-def $eax, debug-instr-number 1
    ; CHECK: $eax = MOVZX32rm16 killed $rdi, {{.*}} debug-instr-number 2
    $ax = KILL $ax, implicit killed $eax
    RET64 $ax

  bb.1:
    $eax = XOR32rr undef $eax, undef $eax, implicit-def dead $eflags
    $ax = KILL $ax, implicit killed $eax
    RET64 $ax

...
